package com.example.hospital.mapper;

import com.example.hospital.pojo.LeaveRequest;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface LeaveMapper {

    @Select("SELECT * FROM leave_request WHERE user_id = #{userId}")
    List<LeaveRequest> findByUserId(Integer userId);

    @Select("SELECT * FROM leave_request")
    List<LeaveRequest> findAll();

    @Select("SELECT * FROM leave_request WHERE id = #{id}")
    LeaveRequest findById(Integer id);

    @Insert("INSERT INTO leave_request(user_id, start_date, end_date, reason, status, created_at, updated_at) " +
            "VALUES(#{userId}, #{startDate}, #{endDate}, #{reason}, #{status}, NOW(), NOW())")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void insertLeave(LeaveRequest leaveRequest);

    @Update("UPDATE leave_request SET status=#{status}, updated_at=NOW() WHERE id=#{id}")
    void updateLeave(LeaveRequest leaveRequest);
}
